G = 100
N = 10
Pg = 1
alpha = c(0.55,0.75,0.54,0.23,0.43,0.56,0.72,0.67,0.47,0.54)
y = c(91.15,121.29,100.49,93.48,107.64,127.22,98.34,74.08,85.57,100.62)
leg = c('', dim=N)
for(i in 1:N)leg[i] = paste('Agent',i,':',expression(alpha),'=',alpha[i],'y=',y[i],sep=' ')

utility <- function(y,x,alpha,Pg,G){
	u = y - x + alpha*Pg*G
	return(u)
}
u0 <- function(y){
	u = y
	return(u)
}

impr = 1

if(impr == 1){ 
	pdf(file='/Users/pawel/thesis/programs/R/output/agents_utility_impr_A.pdf')
}else{ 
	pdf(file='/Users/pawel/thesis/programs/R/output/agents_utility_A.pdf')
}
for(i in 1:N){
	x = seq(0,y[i],1)
	u = array(0, dim=floor(y[i]))
	e = array(0, dim=floor(y[i]))
	w = array(0, dim=floor(y[i]))
	for(j in x){
		u[j] = utility(y[i],j,alpha[i],Pg,G)
		e[j] = max(u[j] - u0(y[i]),0)
	}

	if(impr==1) w = e else w = u
	if(i==1) 
		plot(w, col=i, type='l', ylim=c(0,max(y)), xlim=c(0,max(y)), ann=FALSE, lwd=2)
	else 
		lines(w, col=i, lwd=2)
}

title(xlab= 'Contribution/Tax')
if(impr==1){
	title(ylab= 'Agent`s utility improvement')
}else{
	title(ylab= 'Agent`s utility')
}
if(impr==1){
	title(main='Utility improvements for scenario A', font.main=6)
}else{
	title(main='Utilities for scenario A', font.main=6)
}
legend(x='topright',legend=leg,cex=.8,col=1:N,lwd=2)

dev.off()
